package com.jhhc.StormSurgeForecast.StormSurge.ServiceImpl;

import com.jhhc.StormSurgeForecast.AstronomicalTide.Dao.BDMS_FBC_GRID_FMapper;
import com.jhhc.StormSurgeForecast.StormSurge.Pojo.FBC.BDMS_FBC_GRID_F;
import com.jhhc.StormSurgeForecast.StormSurge.Pojo.GZABO.FeaturesInfo;
import com.jhhc.StormSurgeForecast.StormSurge.Service.BDMS_FBC_GRID_FService;
import com.jhhc.utils.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * (BDMS_FBC_GRID_F)表服务实现类
 *
 * @author makejava
 * @since 2022-09-20 14:08:32
 */
@Service("bdmsFbcGridFService")
public class BDMS_FBC_GRID_FServiceImpl implements BDMS_FBC_GRID_FService {
    @Resource
    private BDMS_FBC_GRID_FMapper BDMSFBCGRIDFMapper;

    @Autowired
    private RedisUtil redisTemplate;

    @Override
    public BDMS_FBC_GRID_F getInfo(String CSCHEMEID,String dtnm) {
        BDMS_FBC_GRID_F bdms_fbc_grid_fs = (BDMS_FBC_GRID_F)redisTemplate.get(CSCHEMEID + dtnm);
        if (bdms_fbc_grid_fs == null) {
            bdms_fbc_grid_fs = BDMSFBCGRIDFMapper.getInfo(CSCHEMEID,dtnm);
            redisTemplate.set(CSCHEMEID + dtnm,bdms_fbc_grid_fs);
            redisTemplate.expire(CSCHEMEID + dtnm,300);
        }
        return bdms_fbc_grid_fs;
    }

    //获取特征信息列表
    @Override
    public List<FeaturesInfo> getBasicInfoList(String dttp) {
        List<BDMS_FBC_GRID_F> bdms_fbc_grid_fs = (List<BDMS_FBC_GRID_F>)redisTemplate.get(dttp);
        if (bdms_fbc_grid_fs == null) {
            bdms_fbc_grid_fs = BDMSFBCGRIDFMapper.getBasicInfoList(dttp);
            redisTemplate.set(dttp,bdms_fbc_grid_fs);
            redisTemplate.expire(dttp,6000);
        }
        List<FeaturesInfo> featuresInfos = new ArrayList<>();
        for (BDMS_FBC_GRID_F bdms_fbc_grid_f : bdms_fbc_grid_fs) {
            FeaturesInfo featuresInfo = new FeaturesInfo();
            featuresInfo.setDtnm(bdms_fbc_grid_f.getDtnm());
            featuresInfo.setTypeofpier(bdms_fbc_grid_f.getTypeofpier());
            featuresInfos.add(featuresInfo);
        }
        return featuresInfos;
    }

    @Override
    public List<BDMS_FBC_GRID_F> getBasicInfo(String CSCHEMEID) {
        List<BDMS_FBC_GRID_F> bdms_fbc_grid_fs = (List<BDMS_FBC_GRID_F>)redisTemplate.get(CSCHEMEID);
        if (bdms_fbc_grid_fs == null) {
            bdms_fbc_grid_fs = BDMSFBCGRIDFMapper.getBasicInfo(CSCHEMEID);
            redisTemplate.set(CSCHEMEID,bdms_fbc_grid_fs);
            redisTemplate.expire(CSCHEMEID,6000);
        }
        return bdms_fbc_grid_fs;
    }
}
